/*
 * Class: GoldPrice
 * 
 * Created on Sep 14, 2013
 * 
 * (c) Copyright by Minh Tran
 * Global Cybersoft VN.
 * Floor 3-4-5, Helios Building, Quang Trung Software City
 */
package com.minh.tran;

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class GoldPrice
{

    /** The Constant LOG. */
    private static final Log LOG = LogFactory.getLog(GoldPrice.class);

    private JFrame frame;

    private final IWebserviceComm comm = new WebserviceCommunication();

    /**
     * Launch the application.
     */
    public static void main(String[] args)
    {
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
        LOG.info("Start main...");
        EventQueue.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    GoldPrice window = new GoldPrice();
                    window.frame.setVisible(true);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public GoldPrice()
    {
        this.initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize()
    {
        this.frame = new JFrame();
        this.frame.setBounds(100, 100, 425, 281);
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.frame.getContentPane().setLayout(new GridLayout(1, 0, 0, 0));

        JPanel panel = new JPanel();
        this.frame.getContentPane().add(panel);

        JButton btnRequest = new JButton("New button");
        btnRequest.addMouseListener(new MouseAdapter()
        {
            @Override
            public void mouseClicked(MouseEvent arg0)
            {
                GoldPrice.this.comm.startProcessing();
            }
        });
        panel.setLayout(new GridLayout(0, 1, 0, 0));
        panel.add(btnRequest);

        JButton btnStop = new JButton("New button");
        btnStop.addMouseListener(new MouseAdapter()
        {
            @Override
            public void mouseClicked(MouseEvent e)
            {
                GoldPrice.this.comm.stopProcessing();
            }
        });
        panel.add(btnStop);

        JTextArea txtPrice = new JTextArea();
        this.frame.getContentPane().add(txtPrice);
    }

}
